package com.sheep.pattern.singleton;

/**
 * 双重校验创建单例模式
 * @author wangze
 * @date 2021-01-12 11:19.
 **/
public class DoubleCheckSingletonTest {


	/**
	 * 防止没有初始化成功  并发问题 用volatile
	 */
	private static volatile DoubleCheckSingletonTest doubleCheckSingletonTest;


	private  DoubleCheckSingletonTest(){

	}

	public static DoubleCheckSingletonTest getInstance(){
			DoubleCheckSingletonTest tmp=doubleCheckSingletonTest;
			if(tmp==null){
				synchronized (DoubleCheckSingletonTest.class){
					if(tmp==null){
						tmp=new DoubleCheckSingletonTest();
						doubleCheckSingletonTest=tmp;
						return tmp;
					}
					return  tmp;
				}
			}
			return  tmp;

	}



}
